class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int ret = 0, n = prices.size();
        for (int i = 0; i < n; i++)
        {
            int j = i;
            while (j + 1 < n && prices[j] < prices[j + 1])
                j++;

            ret += prices[j] - prices[i];
            i = j;
        }

        return ret;
    }
};